package com.jianshuai.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.jianshuai.domain.Menu;
import com.jianshuai.domain.Order;
import com.jianshuai.domain.User;
import com.jianshuai.fallback.OrderFallback;
import com.jianshuai.feign.UserFeignClient;
import com.jianshuai.service.IOrderService;
import com.jianshuai.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService iOrderService;

    @Autowired
    private UserFeignClient feignClient;

    @PostMapping("/order")
    public AjaxResult addOrder(@RequestBody Order order){
        return iOrderService.addOrder(order);
    }

    @GetMapping("/getOrderByUserId/{userId}")
    @SentinelResource(value = "order-limit",blockHandler = "fallback1",blockHandlerClass = OrderFallback.class)
    public User getOrderByUserId(@PathVariable("userId") Long userId){
        System.out.println("用户的id为:================:" + userId);
        User user = feignClient.getId(userId);

        /*List<Order> orderList = iOrderService.getOrderList(userId);
        user.setOrderList(orderList);*/
        return user;
    }

    @PostMapping("/addMenu")
    public AjaxResult addMenu(@RequestBody List<Menu> menus){
        return iOrderService.addMenu(menus);
    }

}
